import { useState } from "react";



function App() {
  const [data,setData] = useState({
    username: '',
    age: ''
  })

  const click = () => {
    setData({
      username: '',
      age: ''
    })
  }
  return (
   <div>
     <h1>受控表单</h1>
     <button onClick={ click }>清空</button>
     <form> 
     <label>
       用户名：
       <input type="text" value={data.username} onChange={(e) => {
         setData({
           ...data,
           username: e.target.value
         })
       }} /> 
       年龄：
       <input type="text" value={data.age} onChange={(e) => {
         setData({
           ...data,
           age: e.target.value
         })
       }} />
     </label>
     </form>
   </div>
  );
}

export default App;

